#ifndef     __BASE_H
#define     __BASE_H

#include <stdint.h>

namespace utils {

using usize_t = uint8_t;
using byte_t = uint8_t;

template <uint8_t BIT_OFFSET, typename T>
inline bool is_set_bit(T value) {
    constexpr T mask = 0x01 << BIT_OFFSET;
    return (value & mask) != 0;
}

template <uint8_t BIT_OFFSET, typename T>
inline bool is_clr_bit(T value) {
    constexpr T mask = 0x01 << BIT_OFFSET;
    return (value & mask) == 0;
}

template <typename DEST, typename SRC>
inline void copy(DEST&& dest, SRC&& src, usize_t len) {
    for (usize_t i = 0; i < len; i ++) {
        dest[i] = src[i];
    }
}

enum class Direct : uint8_t {
    CW = 0, // 顺时针
    CCW = 1, // 逆时针
    BRAKE = 2,
    RELEASE = 3,
};

template <typename ValueType>
struct Number {
    using SelfType = Number<ValueType>;

    bool valid_flag;
    ValueType value;

    inline Number() : valid_flag(false) {}
    inline Number(ValueType val) : valid_flag(true), value(val) {}

    inline operator bool() {
        return valid_flag;
    }

    inline void reset() {
        valid_flag = false;
    }

    inline SelfType& operator=(ValueType val) {
        valid_flag = true;
        value = val;
        return *this;
    }

    inline operator ValueType() {
        return value;
    }
};

using Uint32 = Number<uint32_t>;
using Uint16 = Number<uint16_t>;
using Uint8 = Number<uint8_t>;

}


#endif
